package com.lius.SpringBootStart.intercepter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器
 *
 * @Study 在日常开发中如果使用filter过滤器的话写一堆filter如果为了找某个url在哪个拦截器中需要一个一个去翻
 * 而拦截器中通过CustomWebMvcConfigurer统一注册，集中管理
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        registry.addInterceptor(getLoginIntercepter()).addPathPatterns("/api/v1/pri/**");

        // 实施
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Bean
    public LoginIntercepter getLoginIntercepter() {
        return new LoginIntercepter();
    }
}
